home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / chkreg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  1.6 KB  |  60 lines

  1. /*************************************************************************
  2.  
  3.     CHKREG.C - Validates a key created by REGIT.C
  4.  
  5.    Donated to the Public Domain by Craig Morrison 12 May 1994, use,
  6.    abuse, fold, spindle or mutilate anyway you see fit.
  7.  
  8. *************************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. /* These should be the same as those used in REGIT.C */
  16.  
  17. #define XOR_PRIME      0xFFFFFFFF
  18. #define XOR_CRYPT      0x13579ACE
  19. #define XOR_POST_CRYPT 0x2468BDF0
  20.  
  21. /*************************************************************************
  22.  
  23.     CHKREG accepts two arguments on its command line; The key value in
  24.     hexidecimal generated by REGIT and a string. You should end up with
  25.     XOR_PRIME after the XOR manipulations, if not, then the given key
  26.     was invalid.
  27.  
  28. *************************************************************************/
  29.  
  30. int main(int argc, char *argv[])
  31. {
  32.       long keyval;
  33.       long key;
  34.       char *p;
  35.       char buf[128];
  36.  
  37.       if (argc>2)
  38.       {
  39.             strcpy(buf, argv[1]);
  40.             strupr(buf);
  41.             sscanf(buf, "%8X", &keyval);
  42.             keyval ^= XOR_POST_CRYPT;
  43.  
  44.             strcpy(buf, argv[2]);
  45.             p = strrev(buf);
  46.             while(*p)
  47.             {
  48.                   if (*p=='_')
  49.                         *p = ' ';
  50.  
  51.                   key = (long) toupper(*p);
  52.                   key ^= XOR_CRYPT;
  53.                   keyval ^= key;
  54.                   p++;
  55.             }
  56.             printf("Key value = %08X hex.\n", keyval);
  57.       }
  58.       return 0;
  59. }
  60.